home *** CD-ROM | disk | FTP | other *** search
/ Young Minds / Young Minds Interactive CD-ROM.ISO / sdi / source_c.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-06-18  |  1.4 KB  |  61 lines

  1. /*
  2.  * Copyright 1987 by Mark Weiser.
  3.  * Permission to reproduce and use in any manner whatsoever on Suns is granted
  4.  * so long as this copyright and other identifying marks of authorship
  5.  * in the code and the game remain intact and visible.  Use of this code
  6.  * in other products is reserved to me--I'm working on Mac and IBM versions.
  7.  */
  8.  
  9. /*
  10.  * Little hack to help generate assembler for the source code option.
  11.  */
  12.  
  13. #include <stdio.h>
  14. #include <ctype.h>
  15.  
  16. #define OUTSIZE 64
  17. #define MaxSizeOfAnOctalRepresentation 5
  18.  
  19. char buff[OUTSIZE * MaxSizeOfAnOctalRepresentation];
  20.  
  21. main(argc, argv)
  22. char **argv;
  23. {
  24.     char *p, c;
  25.     int i;
  26.     if (argc < 2) {
  27.         fprintf(stderr, "Need an argument.\n");
  28.         exit(1);
  29.     }
  30.     printf(" .even\n__start_of_text:\n");
  31.     while (! feof(stdin)) {
  32.         p = buff;
  33.         for (i = 0; i < OUTSIZE; i += 1) {
  34.             if ((c = getchar()) != EOF) {
  35.                 if (isalnum(c)  || c == ' ' || c == '*' || c == '/'
  36.                     || c == '#' || c == '<' || c == '>' || c == '.'
  37.                     || c == '_' || c == '[' || c == ']' || c == '(' 
  38.                     || c == ')' || c == '{' || c == '}'
  39.                     ) {
  40.                     *p++ = c;
  41.                 } else {
  42.                     *p++ = '\\';
  43.                     sprintf(p, "%o", (unsigned int)c);
  44.                     i += strlen(p);
  45.                     p += strlen(p);
  46.                 }
  47.             } else {
  48.                 goto done;
  49.             }
  50.         }
  51. done:
  52.         *p = '\0';
  53.         printf(" .ascii \"%s\"\n", buff);
  54.     }
  55.     printf(" .ascii \"\\0\"\n",'\\');
  56.     printf(" .even\n");
  57.     printf(" .globl _%s\n", argv[1]);
  58.     printf("_%s:\n", argv[1]);
  59.     printf(" .long __start_of_text\n");
  60. }
  61.